package hopital.infermier;

import hopital.docteur.*;
import hopital.orm.Consultation;
import hopital.orm.Patient;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PatientInterface extends javax.swing.JInternalFrame {

    public PatientInterface() {
        initComponents();
        table1.addColumn("DATE");
        table1.addColumn("MALADIE");
        table1.addColumn("ORDONNENCE");
        table1.revalidate();
        initiallize();
    }

    public final void initiallize() {
        try {
            List<Object> _list = hopital.sql.SqlDatabase.getDatabase().retrive(new Patient());
            list1.removeItems();
            for (Object _doc : _list) {
                list1.addItem(_doc);
            }
            search1.setList(list1);
        } catch (Exception ex) {
            Logger.getLogger(PatientInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @SuppressWarnings("unchecked")
    private void initComponents() {//GEN-BEGIN:initComponents

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        list1 = new hopital.ui.List();
        _panel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        _nom = new javax.swing.JTextField();
        _prenom = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        _telephone = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        _adresse = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        table1 = new hopital.ui.Table();
        jToolBar1 = new javax.swing.JToolBar();
        search1 = new hopital.ui.Search();

        setFrameIcon(null);

        jPanel2.setLayout(new java.awt.BorderLayout());

        list1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(list1);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jSplitPane1.setLeftComponent(jPanel2);

        jLabel1.setText("Nom");

        jLabel2.setText("Prenom");

        jLabel4.setText("Adresse");

        _adresse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _adresseActionPerformed(evt);
            }
        });

        jLabel5.setText("Telephone");

        jScrollPane2.setViewportView(table1);

        javax.swing.GroupLayout _panelLayout = new javax.swing.GroupLayout(_panel);
        _panel.setLayout(_panelLayout);
        _panelLayout.setHorizontalGroup(
            _panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(_panelLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 477, Short.MAX_VALUE)
                    .addGroup(_panelLayout.createSequentialGroup()
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(_panelLayout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(_telephone, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(_panelLayout.createSequentialGroup()
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(_prenom, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(_panelLayout.createSequentialGroup()
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(_nom, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(_panelLayout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(_adresse, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        _panelLayout.setVerticalGroup(
            _panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(_panelLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(_panelLayout.createSequentialGroup()
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(_nom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(_prenom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addComponent(_telephone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_adresse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSplitPane1.setRightComponent(_panel);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.add(search1);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        pack();
    }//GEN-END:initComponents

    private void list1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list1ValueChanged
        if (list1.getSelectedValue() != null) {
            Patient _patient = (Patient) list1.getSelectedValue();
            _nom.setText(_patient.getNom());
            _prenom.setText(_patient.getPrenom());
            _adresse.setText(_patient.getAdresse());
            _telephone.setText(_patient.getTelephone());
            try {
                Consultation _cons=new Consultation();
            _cons.setPatient(_patient.getId());
            List<Object> _list=hopital.sql.SqlDatabase.getDatabase().retrive(_cons);
            table1.removeRows();
            for(Object o:_list){
                Vector v=new Vector();
                v.add(((Consultation) o).getDate());
                v.add(((Consultation) o).getMaladie());
                v.add(((Consultation) o).getOrdonnance());
                table1.addRow(v);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        }
    }//GEN-LAST:event_list1ValueChanged

    private void _adresseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__adresseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event__adresseActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField _adresse;
    private javax.swing.JTextField _nom;
    protected javax.swing.JPanel _panel;
    private javax.swing.JTextField _prenom;
    private javax.swing.JTextField _telephone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private hopital.ui.List list1;
    private hopital.ui.Search search1;
    private hopital.ui.Table table1;
    // End of variables declaration//GEN-END:variables
}
